/*
 *  Author: Honrun
 */
#ifndef _DevicesQueue_H_
#define _DevicesQueue_H_

#include "DevicesTSI.h"



#define QUEUE_MAX_LENGTH         (2048)

#define QUEUE_UART0_READ_LENGTH  (1024)
#define QUEUE_UART1_READ_LENGTH  (1024)
#define QUEUE_UART2_READ_LENGTH  (1024)

#define QUEUE_KEY_INPUT_LENGTH   (256)
#define QUEUE_KEY_TOUCH_LENGTH   (64)
#define QUEUE_IFRP_ENCODE_LENGTH (1024)
#define QUEUE_IFRP_DECODE_LENGTH (1024)




/* 使x对n字节对齐 */
#define queueRoundUp(x, n) (((x) + (n) - 1) & (~((n) - 1)))


typedef enum {
    queueNormal = 0,
    queueError,
    queueNull,
    queueEmpty,
    queueFull,
}enumQueueState;

typedef enum {
    queueModeNormal = 0,    /* 覆盖模式 */
    queueModeLock,          /* 锁定模式 */
}enumQueueMode;



typedef struct{
    char *pcName;

    uint8_t *pHead;
    uint8_t *pTail;
    uint8_t *pReadFrom;
    uint8_t *pWriteTo;

    int32_t length;

    enumQueueMode mode;
}QueueType;



extern QueueType g_TypeQueueUart0Read;
extern QueueType g_TypeQueueUart1Read;
extern QueueType g_TypeQueueUart2Read;

extern QueueType g_TypeQueueKeyInput;
extern QueueType g_TypeQueueKeyTouch[KEY_TOUCH_CHANNEL_NUMBER];

extern QueueType g_TypeQueueIFRPDecode;
extern QueueType g_TypeQueueIFRPEncode;



enumQueueState enumQueueInit(void);
enumQueueState enumQueueCreate(QueueType *pTypeQueue, char *pcName, uint8_t *pucBuff, int32_t iLength, enumQueueMode enumMode);
enumQueueState enumQueueGetState(QueueType *pTypeQueue);
enumQueueState enumQueueSetState(QueueType *pTypeQueue, enumQueueState enumState);
int32_t iQueueGetLengthOfOccupy(QueueType *pTypeQueue);
int32_t iQueueGetLengthOfOccupyNeed(QueueType *pTypeQueue, uint8_t ucByte);
int32_t iQueueGetLengthOfSeparetor(QueueType *pTypeQueue, uint8_t ucByte);
int32_t iQueueGetLengthOfRemaining(QueueType *pTypeQueue);
enumQueueState enumQueuePushByte(QueueType *pTypeQueue, uint8_t ucData);
enumQueueState enumQueuePopByte(QueueType *pTypeQueue, uint8_t *pucData);
enumQueueState enumQueueViewByte(QueueType *pTypeQueue, uint8_t *pucData);
enumQueueState enumQueuePushDatas(QueueType *pTypeQueue, void *pvBuff, int32_t iLength);
enumQueueState enumQueuePopDatas(QueueType *pTypeQueue, void *pvBuff, int32_t iLength);
enumQueueState enumQueueViewDatas(QueueType *pTypeQueue, void *pvBuff, int32_t iLength);
enumQueueState enumQueuePopDatasNeed(QueueType *pTypeQueue, void *pvBuff, int32_t iLength, uint8_t ucByte);
enumQueueState enumQueueViewDatasNeed(QueueType *pTypeQueue, void *pvBuff, int32_t iLength, uint8_t ucByte);

#endif
